package com.retallife.user.controller;

import com.retallife.user.exception.Result;
import com.retallife.user.pojo.Complaint.UserComplaintVo;
import com.retallife.user.service.Complaint.ComplaintService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@Api(tags = "用户投诉类")
@RequestMapping(method = {RequestMethod.POST, RequestMethod.GET})
public class ComplaintController {

    @Autowired
    ComplaintService complaintService;

    @ApiOperation(value = "查询某个用户的投诉信息")
    @RequestMapping("FindComplaints")
    public List<UserComplaintVo> FindComplaints(@RequestParam String userComplaintName) {
        return complaintService.FindComplaints(userComplaintName);
    }

    @ApiOperation(value = "增加用户提交的投诉信息")
    @RequestMapping("AddComplaints")
    public Result AddComplaints(@RequestBody UserComplaintVo userComplaintVo){
        //获取当地的时间
        Date data = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = dateFormat.format(data);
        //设置特征码
        String state = "0";
        userComplaintVo.setUserComplaintData(time);
        userComplaintVo.setUserComplaintstate(state);
        int result = complaintService.AddComplaints(userComplaintVo);
        if (result > 0){
            return Result.ok("投诉成功");
        }
        return Result.ok("投诉失败");
    }

}
